

from PIL import Image

import pytesseract

# 含羞草

# 修改图片的尺寸
def ResizeImage(filein, fileout, width, height, type):
    img = Image.open(filein)

    out = img.resize((width, height), Image.ANTIALIAS)

    out.save(fileout, type)


# 裁剪图片 文件路径、裁剪开始点、裁剪长度宽度、输出图片名
def cutImage(img_file, pos_x, pos_y, width, height, out_file):
    img = Image.open(img_file)
    region = (pos_x, pos_y, pos_x + width, pos_y + height)
    cropImg = img.crop(region)
    cropImg.save(out_file)
    print("exported:", out_file)


# 识别图片中内容，输出
def ocr(file):

    image = Image.open(file)
    # 识别图片
    content = pytesseract.image_to_string(image)
    # 输出内容
    print(content)

if __name__ == "__main__":

 for i in range(2,19):
    filein = r'goisi_k'+str(i)+'.png'
    fileout = r'black'+str(i)+'.png'
    width = 53
    height = 30
    type = 'png'
    ResizeImage(filein, fileout, width, height, type)
